#ifndef CONTROLTHREAD_H
#define CONTROLTHREAD_H

#include <QtCore>
#include <QTimer>

#include <newmat11/newmat.h>
#include "MM3AWidget.h"
#include "Joystick.h"

/** \brief Control thread for the manipulator

Control Thread is used to separate the manipulator control functions from the main thread enabling them to run at a higher refresh rate*/
class ControlThread : public QThread
{
    Q_OBJECT

public:
    ControlThread(QObject *parent = 0, Joystick *joystick=0);

    /** Pointer to MM3A */
    MM3AWidget *mm3a;

    /** Timer for control thread */
    QTimer *controlTimer;

    /** Magnitude of input velocity */
    double velMag;
    /** Direction of input velocity */
    double velDir;

    /** Mode of experiment. 0 = exp mode, 1 = free mode */
    bool mode;

    /** flag to check if Phantom Omni is selected */
    bool omni;
    /** flag to check if Space Explorer is selected */
    bool spaceExp;

    /** Pointer to store joystick object from parent widget. Needed to read joystick data members*/
    Joystick *tempJoystick;

    /** Open thread */
    void open();
    /** Close thread */
    void close();

public slots:
    virtual void run();

    /** Reset experiment */
    void reset();

    /** To simulate manipulator i.e. no serial commands are sent to the manipulator */
    void simulate();

private:
    /** counts the number of corners reached */
    int cornerCount;

    /** position of corners in pixels */
    int corners[4][2];

};



#endif // CONTROLTHREAD_H
